<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="导入批次号" prop="batchNo">
        <el-input
          v-model="queryParams.batchNo"
          placeholder="请输入导入批次号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车辆编码" prop="vehiclesCode">
        <el-input
          v-model="queryParams.vehiclesCode"
          placeholder="请输入车辆编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车辆设备名称" prop="vehiclesName">
        <el-input
          v-model="queryParams.vehiclesName"
          placeholder="请输入车辆设备名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车牌号码" prop="vehiclesNumber">
        <el-input
          v-model="queryParams.vehiclesNumber"
          placeholder="请输入车牌号码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="处理状态" prop="processStatus">
        <el-select v-model="queryParams.processStatus" placeholder="请选择处理状态" clearable>
          <el-option
            v-for="dict in dict.type.sys_common_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    
    <el-row :gutter="10" class="mb8">
      <!--
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['erecord:vehiclesImportDetail:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['erecord:vehiclesImportDetail:edit']"
        >修改</el-button>
      </el-col>
      -->
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['erecord:vehiclesImportDetail:remove']"
        >删除</el-button>
      </el-col>
      <!--
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['erecord:vehiclesImportDetail:export']"
        >导出</el-button>
      </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    
    
    <el-table v-loading="loading" :data="vehiclesImportDetailList" @selection-change="handleSelectionChange" >
      
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column align="center" label="序号" width="55">
        <template slot-scope="scope">
          <span>{{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="id" align="center" prop="id" v-if="false" width="100"/>
      
      <el-table-column label="导入批次号" align="center" prop="batchNo" width="180"/>
      <el-table-column label="车辆编码" align="center" prop="vehiclesCode" width="100"/>

      <el-table-column label="服务部门" align="center" prop="deptIdImport" width="110"/>

      <el-table-column label="服务类型" align="center" prop="serviceTypeImport" width="110"/>
      <el-table-column label="车辆设备名称" align="center" prop="vehiclesName" width="120"/>
      <el-table-column label="车辆类型" align="center" prop="vehiclesType" width="100"/>
      <el-table-column label="车牌号码" align="center" prop="vehiclesNumber" width="100"/>
      <el-table-column label="品牌" align="center" prop="brand" width="100"/>
      <el-table-column label="规格型号" align="center" prop="specificationMode" />
      <el-table-column label="车辆注册日期" align="center" prop="registerDate" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.registerDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>

      <el-table-column label="纯电动" align="center" prop="evFlagImport" />
      <el-table-column label="总质量" align="center" prop="totalWeight" />

      <el-table-column label="是否加装GPS" align="center" prop="gpsFlagImprort" />
      <el-table-column label="车辆行驶证编号" align="center" prop="vehicleLicenseNo" width="120"/>

      <el-table-column label="驾驶员" align="center" prop="employeeCodeImport" />
      <el-table-column label="手机号码" align="center" prop="phone" width="110"/>
      <el-table-column label="准驾车型" align="center" prop="drivingVehiclesType" />
      <el-table-column label="保险期限" align="center" prop="insureDate" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.insureDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="驾驶证有效期" align="center" prop="drivingLicenseValidityDate" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.drivingLicenseValidityDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="行驶证有效期" align="center" prop="travelLicenseValidityDate" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.travelLicenseValidityDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>

      <el-table-column label="驾驶证照片" align="center" prop="drivingLicensePic" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.drivingLicensePicUrl" :width="50" :height="50" />
        </template>
      </el-table-column>
      <el-table-column label="行驶证照片" align="center" prop="travelLicensePic" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.travelLicensePicUrl" :width="50" :height="50" />
        </template>
      </el-table-column>
      <el-table-column label="正前面照片" align="center" prop="frontPic" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.frontPicUrl" :width="50" :height="50" />
        </template>
      </el-table-column>
      <el-table-column label="正侧面照片" align="center" prop="sidePic" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.sidePicUrl" :width="50" :height="50" />
        </template>
      </el-table-column>
      <el-table-column label="正后面照片" align="center" prop="behindPic" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.behindPicUrl" :width="50" :height="50" />
        </template>
      </el-table-column>

      <el-table-column label="处理状态" align="center" prop="processStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_common_status" :value="scope.row.processStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="处理信息" align="center" prop="processMsg" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="创建人" align="center" prop="createBy" />
      <el-table-column label="更新时间" align="center" prop="updateTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="更新人" align="center" prop="updateBy" />      
      <!--
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['erecord:vehiclesImportDetail:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['erecord:vehiclesImportDetail:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
      -->
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改车辆导入明细对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="导入批次号" prop="batchNo">
          <el-input v-model="form.batchNo" placeholder="请输入导入批次号" />
        </el-form-item>
        <el-form-item label="车辆编码" prop="vehiclesCode">
          <el-input v-model="form.vehiclesCode" placeholder="请输入车辆编码" />
        </el-form-item>
        <el-form-item label="服务部门" prop="deptId">
          <el-input v-model="form.deptId" placeholder="请输入服务部门" />
        </el-form-item>
        <el-form-item label="服务部门-import" prop="deptIdImport">
          <el-input v-model="form.deptIdImport" placeholder="请输入服务部门-import" />
        </el-form-item>
        <el-form-item label="服务类型-import" prop="serviceTypeImport">
          <el-input v-model="form.serviceTypeImport" placeholder="请输入服务类型-import" />
        </el-form-item>
        <el-form-item label="车辆设备名称" prop="vehiclesName">
          <el-input v-model="form.vehiclesName" placeholder="请输入车辆设备名称" />
        </el-form-item>
        <el-form-item label="车牌号码" prop="vehiclesNumber">
          <el-input v-model="form.vehiclesNumber" placeholder="请输入车牌号码" />
        </el-form-item>
        <el-form-item label="品牌" prop="brand">
          <el-input v-model="form.brand" placeholder="请输入品牌" />
        </el-form-item>
        <el-form-item label="规格型号" prop="specificationMode">
          <el-input v-model="form.specificationMode" placeholder="请输入规格型号" />
        </el-form-item>
        <el-form-item label="车辆注册日期" prop="registerDate">
          <el-date-picker clearable
            v-model="form.registerDate"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="请选择车辆注册日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="纯电动" prop="evFlag">
          <el-input v-model="form.evFlag" placeholder="请输入纯电动" />
        </el-form-item>
        <el-form-item label="纯电动-import" prop="evFlagImport">
          <el-input v-model="form.evFlagImport" placeholder="请输入纯电动-import" />
        </el-form-item>
        <el-form-item label="总质量" prop="totalWeight">
          <el-input v-model="form.totalWeight" placeholder="请输入总质量" />
        </el-form-item>
        <el-form-item label="是否加装GPS" prop="gpsFlag">
          <el-input v-model="form.gpsFlag" placeholder="请输入是否加装GPS" />
        </el-form-item>
        <el-form-item label="是否加装GPS-imprort" prop="gpsFlagImprort">
          <el-input v-model="form.gpsFlagImprort" placeholder="请输入是否加装GPS-imprort" />
        </el-form-item>
        <el-form-item label="车辆行驶证编号" prop="vehicleLicenseNo">
          <el-input v-model="form.vehicleLicenseNo" placeholder="请输入车辆行驶证编号" />
        </el-form-item>
        <el-form-item label="驾驶员" prop="employeeCode">
          <el-input v-model="form.employeeCode" placeholder="请输入驾驶员" />
        </el-form-item>
        <el-form-item label="驾驶员-import" prop="employeeCodeImport">
          <el-input v-model="form.employeeCodeImport" placeholder="请输入驾驶员-import" />
        </el-form-item>
        <el-form-item label="手机号码" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入手机号码" />
        </el-form-item>
        <el-form-item label="保险期限" prop="insureDate">
          <el-date-picker clearable
            v-model="form.insureDate"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="请选择保险期限">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="驾驶证有效期" prop="drivingLicenseValidityDate">
          <el-date-picker clearable
            v-model="form.drivingLicenseValidityDate"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="请选择驾驶证有效期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="行驶证有效期" prop="travelLicenseValidityDate">
          <el-date-picker clearable
            v-model="form.travelLicenseValidityDate"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="请选择行驶证有效期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="驾驶证照片" prop="drivingLicensePic">
          <el-input v-model="form.drivingLicensePic" placeholder="请输入驾驶证照片" />
        </el-form-item>
        <el-form-item label="行驶证照片" prop="travelLicensePic">
          <el-input v-model="form.travelLicensePic" placeholder="请输入行驶证照片" />
        </el-form-item>
        <el-form-item label="正前面照片" prop="frontPic">
          <el-input v-model="form.frontPic" placeholder="请输入正前面照片" />
        </el-form-item>
        <el-form-item label="正侧面照片" prop="sidePic">
          <el-input v-model="form.sidePic" placeholder="请输入正侧面照片" />
        </el-form-item>
        <el-form-item label="正后面照片" prop="behindPic">
          <el-input v-model="form.behindPic" placeholder="请输入正后面照片" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="处理状态" prop="processStatus">
          <el-select v-model="form.processStatus" placeholder="请选择处理状态">
            <el-option
              v-for="dict in dict.type.sys_common_status"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="处理信息" prop="processMsg">
          <el-input v-model="form.processMsg" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listVehiclesImportDetail, getVehiclesImportDetail, delVehiclesImportDetail, addVehiclesImportDetail, updateVehiclesImportDetail } from "@/api/erecord/vehiclesImportDetail";

export default {
  name: "VehiclesImportDetail",
  dicts: ['sys_common_status'],
  data() {
    return {
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 车辆导入明细表格数据
      vehiclesImportDetailList: [],
      // 弹出层标题
      title: "",
      // 是否新增
      isAdd : true,      
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        batchNo: undefined,
        vehiclesCode: undefined,
        deptId: undefined,
        deptIdImport: undefined,
        serviceType: undefined,
        serviceTypeImport: undefined,
        vehiclesName: undefined,
        vehiclesType: undefined,
        vehiclesNumber: undefined,
        brand: undefined,
        specificationMode: undefined,
        registerDate: undefined,
        evFlag: undefined,
        evFlagImport: undefined,
        totalWeight: undefined,
        gpsFlag: undefined,
        gpsFlagImprort: undefined,
        vehicleLicenseNo: undefined,
        employeeCode: undefined,
        employeeCodeImport: undefined,
        phone: undefined,
        drivingVehiclesType: undefined,
        insureDate: undefined,
        drivingLicenseValidityDate: undefined,
        travelLicenseValidityDate: undefined,
        drivingLicensePic: undefined,
        travelLicensePic: undefined,
        frontPic: undefined,
        sidePic: undefined,
        behindPic: undefined,
        processStatus: undefined,
        processMsg: undefined,
        orderByColumn: "update_time,vehiclesCode",
        isAsc: "desc,asc",
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        batchNo: [
          { required: true, message: "导入批次号不能为空", trigger: "blur" }
        ],
        vehiclesCode: [
          { required: true, message: "车辆编码不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    const batchNo = this.$route.params && this.$route.params.batchNo;
    //console.log("--------------------------  " , batchNo)
    if (batchNo) {
      this.queryParams.batchNo = batchNo;
      //this.form.batchNo = batchNo;
    }        
    this.getList();
  },
  methods: {
    /** 查询车辆导入明细列表 */
    getList() {
      this.loading = true;
      listVehiclesImportDetail(this.queryParams).then(response => {
        this.vehiclesImportDetailList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        batchNo: undefined,
        vehiclesCode: undefined,
        deptId: undefined,
        deptIdImport: undefined,
        serviceType: undefined,
        serviceTypeImport: undefined,
        vehiclesName: undefined,
        vehiclesType: undefined,
        vehiclesNumber: undefined,
        brand: undefined,
        specificationMode: undefined,
        registerDate: undefined,
        evFlag: undefined,
        evFlagImport: undefined,
        totalWeight: undefined,
        gpsFlag: undefined,
        gpsFlagImprort: undefined,
        vehicleLicenseNo: undefined,
        employeeCode: undefined,
        employeeCodeImport: undefined,
        phone: undefined,
        drivingVehiclesType: undefined,
        insureDate: undefined,
        drivingLicenseValidityDate: undefined,
        travelLicenseValidityDate: undefined,
        drivingLicensePic: undefined,
        travelLicensePic: undefined,
        frontPic: undefined,
        sidePic: undefined,
        behindPic: undefined,
        remark: undefined,
        processStatus: undefined,
        processMsg: undefined,
        createTime: undefined,
        createBy: undefined,
        updateTime: undefined,
        updateBy: undefined,
        delFlag: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.isAdd = true;
      this.title = "添加车辆导入明细";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.loading = true;
      this.reset();
      const id = row.id || this.ids
      getVehiclesImportDetail(id).then(response => {
        this.loading = false;
        this.form = response.data;
        this.open = true;
        this.isAdd = false;
        this.title = "修改车辆导入明细";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.buttonLoading = true;
          if (this.isAdd == false) {
            updateVehiclesImportDetail(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          } else {
            addVehiclesImportDetail(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除数据').then(() => {
        this.loading = true;
        return delVehiclesImportDetail(ids);
      }).then(() => {
        this.loading = false;
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      }).finally(() => {
        this.loading = false;
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('erecord/vehiclesImportDetail/export', {
        ...this.queryParams
      }, `vehiclesImportDetail_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
